package com.kob.backend.service.impl.pk;

import com.kob.backend.service.pk.PkService;
import com.kob.backend.websocket.Game;
import com.kob.backend.websocket.WebSocketServer;
import org.springframework.stereotype.Service;

@Service
public class PkServiceImpl implements PkService {
    @Override
    public String startGame(Integer aId,Integer aBotId, Integer bId,Integer bBotId) {
        WebSocketServer.startGame(aId,aBotId, bId,bBotId);
        return "start game success";
    }

    @Override
    public String ReceiveBotMove(Integer userId, Integer direction) {
        if(WebSocketServer.users.get(userId) != null) {
            Game game = WebSocketServer.users.get(userId).game;
            if(game != null) {
                if (game.getPlayerA().getId().equals(userId)) {
                    game.setNextStepA(direction);
                } else if (game.getPlayerB().getId().equals(userId)) {
                        game.setNextStepB(direction);
                }
            }
        }
        return "receive move success";
    }
}
